package com.saa.application.controller;

import com.saa.application.po.SaaApplicationInfo;
import com.saa.application.service.ApplicationInfoService;
import com.saa.application.vo.SaaApplicationInfoVo;
import com.saa.common.vo.OmsResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/applicationinfo")
public class ApplicationInfoController {
    private Logger logger = LoggerFactory.getLogger(ApplicationInfoController.class);

    @Autowired
    private ApplicationInfoService applicationInfoService;

    @PostMapping("/insertApplicationInfo")
    public OmsResultVo insertApplicationInfo(@RequestBody SaaApplicationInfo saaApplicationInfo) {
        try {
            return applicationInfoService.insertApplicationInfo(saaApplicationInfo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "新增失败", null);
        }
    }

    @PostMapping("/getApplicationInfoPage")
    public OmsResultVo getApplicationInfoPage(@RequestBody SaaApplicationInfoVo saaApplicationInfo) {
        try {
//            System.out.println(applicationInfoService.getApplicationInfoPage(applicationInfo, applicationInfo.getPage(), applicationInfo.getPageSize()));
            return applicationInfoService.getApplicationInfoPage(saaApplicationInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

    @PostMapping("/getApplicationInfo")
    public OmsResultVo getApplicationInfo(@RequestBody SaaApplicationInfo saaApplicationInfo) {
        try {
            return applicationInfoService.getApplicationInfo(saaApplicationInfo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

    @PostMapping("/getApplicationNameList")
    public OmsResultVo getApplicationList() {
        try {
            return applicationInfoService.getApplicationList();
        } catch (Exception e) {
            return OmsResultVo.builder(500, "查询失败", null);
        }
    }

    @PostMapping("/updateApplicationInfo")
    public OmsResultVo updateApplicationInfo(@RequestBody SaaApplicationInfo saaApplicationInfo) {
        try {
            return applicationInfoService.updateApplicationInfo(saaApplicationInfo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "更新失败", null);
        }
    }

    @PostMapping("/deleteApplicationInfo")
    public OmsResultVo deleteApplicationInfo(@RequestBody SaaApplicationInfo saaApplicationInfo) {
        try {
            return applicationInfoService.deleteApplicationInfo(saaApplicationInfo);
        } catch (Exception e) {
            return OmsResultVo.builder(500, "删除失败", null);
        }
    }
}
